package com.graduate.daydayup.activity

import android.os.Bundle
import com.blankj.utilcode.util.ToastUtils
import com.graduate.daydayup.R
import com.graduate.daydayup.base.BaseActivity
import com.graduate.daydayup.event.EventMessage
import com.graduate.daydayup.event.REFRESH_NOTE
import com.graduate.daydayup.room.NoteContent
import com.graduate.daydayup.room.noteContentDao
import com.graduate.daydayup.room.noteTypeDao
import com.graduate.daydayup.view.MyPickerView
import kotlinx.android.synthetic.main.activity_addcontent.*
import org.greenrobot.eventbus.EventBus
import java.util.ArrayList

class NoteContentAddActivity:BaseActivity() {
    override fun setTitle()="添加便签内容"

    override fun getLayout()= R.layout.activity_addcontent

    override fun setTextRight()=""

    override fun setImgRightListener() {

    }

    override fun isAddToolbar()=true

    override fun initViewIds() {

    }

    override fun initView() {
        val myPickerView = MyPickerView(this)
        val typeList = arrayListOf<String>()
        val allNotes = noteTypeDao?.getAllNotes()
        if (allNotes != null) {
            for (bean in allNotes){
                typeList.add(bean.name)
            }
        }
        myPickerView.setPicker(typeList)
        stv_selectnotes.setOnSuperTextViewClickListener {
            myPickerView.show()
        }
        myPickerView.setOnoptionsSelectListener { options1, option2, options3 ->
            stv_selectnotes.setLeftString("")
            stv_selectnotes.setCenterString(typeList[options1])
        }
        btn_save.setOnClickListener {
            when{
                et_notecontent.text.toString().isEmpty()->ToastUtils.showShort("便签分类为空")
                stv_selectnotes.centerString.isEmpty()->ToastUtils.showShort("便签内容为空")
                else-> {
                    noteContentDao?.addNoteContent(NoteContent(0,stv_selectnotes.centerString, et_notecontent.text.toString()))
                    ToastUtils.showShort("添加成功")
                    EventBus.getDefault().post(EventMessage(REFRESH_NOTE))
                    finish()
                }
            }

        }
    }

    override fun initData(savedInstanceState: Bundle?) {

    }
}